package com.hxzy.module.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzy.module.store.api.store.req.StoreReq;
import com.hxzy.module.store.api.store.resp.StoreResp;
import com.hxzy.module.store.entity.Store;
import com.hxzy.module.store.mapstruct.StoreAccountMapStruct;
import com.hxzy.module.store.service.StoreService;
import com.hxzy.module.store.mapper.StoreMapper;
import org.springframework.stereotype.Service;

/**
* @author 11452
* @description 针对表【store(门店表)】的数据库操作Service实现
* @createDate 2024-01-24 14:23:29
*/
@Service
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store>
    implements StoreService{


    @Override
    public PageInfo<StoreResp> storeList(StoreReq req) {
        //当前登录用户的商户ID
        long merchantId=1L;

        return PageHelper.startPage(req.getPageNum(),req.getPageSize()).
                doSelectPageInfo(()->{
                     this.baseMapper.findStoreListRespByCondition(req,merchantId);
                });
    }

    /**
     * 根据storeId查询数据
     * @param storeId
     * @param merchantId
     * @return
     */
    @Override
    public StoreResp findByStoreId(Long storeId, long merchantId) {
        LambdaQueryWrapper<Store>  queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Store::getId, storeId);
        queryWrapper.eq(Store::getMerchantId,merchantId);
        Store store = this.getOne(queryWrapper);
        return StoreAccountMapStruct.INSTANCE.convert(store);
    }
}




